package com.jiangnan.controller;

import com.github.tocrhz.mqtt.annotation.MqttSubscribe;
import com.jiangnan.pojo.MessageDetail;
import com.jiangnan.utils.FastjsonUtils;
import com.jiangnan.view.FullScreenView;
import org.eclipse.paho.client.mqttv3.MqttMessage;
import org.springframework.stereotype.Component;

import java.nio.charset.StandardCharsets;

@Component
public class MqttMessageHandler {

    /**
     * topic = test/+
     */
    @MqttSubscribe("mqtt/face/1002913/+")
    public void Rec(String topic, MqttMessage message) {
        MessageDetail messageDetail = FastjsonUtils.json2Object(message.getPayload(), MessageDetail.class);
        FullScreenView view = new FullScreenView();
        view.setPic(messageDetail.getPic());
        view.setPersonName(messageDetail.getPersonName());
        view.setIdCard(messageDetail.getIdCard());
        view.setTime(messageDetail.getTime());
        view.run();
    }

    @MqttSubscribe("mqtt/face/heartbeat")
    public void heartbeat(MqttMessage message) {
        System.out.println(message);
    }

}
